<?php 


$hostname_bb_base = "localhost";
$database_bb_base = "bbtools";
$username_bb_base = "root";
$password_bb_base = "";
$bb_base = mysql_pconnect($hostname_bb_base, $username_bb_base, $password_bb_base) or trigger_error(mysql_error(),E_USER_ERROR); 

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

// checks if an user exists in our database and adds him if not
function checkUserExists($username) { 	
	global $bb_base;
	global $database_bb_base;
	mysql_select_db($database_bb_base, $bb_base);
	$query_string = sprintf("SELECT * FROM manager WHERE manager.login = %s",GetSQLValueString($username,"text")) ;
	$query_result = mysql_query($query_string, $bb_base) or die(mysql_error());
	$totalRows = mysql_num_rows($query_result);	
	
	if($totalRows > 0) { 
		return true;
	} else {
		mysql_select_db($database_bb_base, $bb_base);
		$query_string = sprintf("INSERT INTO manager (login, type) VALUES (%s, 1)",GetSQLValueString($username,"text"));
		$query_result = mysql_query($query_string, $bb_base) or die(mysql_error());
		return false;	
	}
	mysql_free_result($query_result);
}

function getNavigationOptions() {
	global $bb_base;
	global $database_bb_base;
	mysql_select_db($database_bb_base, $bb_base);
	$query_string = sprintf("SELECT * FROM module WHERE 1");
	$query_result = mysql_query($query_string, $bb_base) or die(mysql_error());
	return $query_result;
}

?>